﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CompilationFactures.Enums;
using System.IO;

namespace CompilationFactures.Objects
{
    public class FactureGarage : Facture
    {
        public FactureGarage()
        {

        }

        public FactureGarage(int _NoFacture, List<Article> _Articles)
            : base(_NoFacture, _Articles)
        {

        }

        private FactureGarage(FactureGarage factGar)
        {
            this.noFacture = factGar.noFacture;
            this.operation = factGar.operation;
            this.listeArticles = factGar.copierArticles();
        }

        public override string DescriptionType
        {
            get
            {
                return "Facture de garage";
            }
        }

        public override string Type
        {
            get
            {
                return "Garage";
            }
        }

        public override Facture Copier()
        {
            return new FactureGarage(this);
        }

        static public FactureGarage operator +(FactureGarage fact1, FactureGarage fact2)
        {
            //TODO Compare article avec le nom et le prix
            FactureGarage factTotal = new FactureGarage(fact1);

            foreach (Article article in fact2.ListeArticles)
            {
                Article ArticleTotal = factTotal.ListeArticles.Find(art => String.Equals(art.Item, article.Item) && (art.Prix == article.Prix));

                if (ArticleTotal != null)
                {
                    ArticleTotal.Quantite = article.Quantite + ArticleTotal.Quantite;
                }
                else
                {
                    factTotal.ListeArticles.Add(article);
                }
            }

            return factTotal;
        }

        static public FactureGarage operator -(FactureGarage fact1, FactureGarage fact2)
        {
            //TODO Compare article avec le nom et le prix
            FactureGarage factTotal = new FactureGarage(fact1);

            foreach (Article article in fact2.ListeArticles)
            {
                Article ArticleTotal = factTotal.ListeArticles.Find(art => String.Equals(art.Item, article.Item) && (art.Prix == article.Prix));

                if (ArticleTotal != null)
                {
                    ArticleTotal.Quantite = ArticleTotal.Quantite - article.Quantite;
                }
            }

            return factTotal;
        }
    }
}
